/*
	jQuery - siteFeature Plugin
	@copyright Michael Kafka - http://www.makfak.com
	@version 1.7.2
*/
(function($){

	$.fn.siteFeature = function(options) {
		var opts = $.extend({}, $.fn.siteFeature.defaults, options);

		return this.each(function(i) {
			obj = $(this);
			var settings = {};
				settings.which = i;
			// contains all DOM traversal and manipulation
			createFeature(opts,settings);
			// configures the Feature based on the options
			customizeFeature(opts,settings);
			// binds all associated events
			eventFeature(opts,settings);
		}); 
    }; // end $.fn.siteFeature


	$.fn.siteFeature.defaults = {
		outputElementId: 'siteFeature',			// this is the ID given to the container div generated by siteFeature
		txtBoxIdPrefix: 'txtBox',				// creates the naming convention for the TextBox (ie: txtBoxContainer) 
		imgBgIdPrefix: 'imgBg',					// creates the naming convention for the ImageBackgounds (ie: imgBgContainer)
		tabIdPrefix: 'tab',						// creates the naming convention for the Tabs (ie: tabContainer)
		titleText: 'h3',						// identifies the Title Text for manipulation
		containerWidth: '1100px',				// sets the generated Container's width
		containerHeight: '408px',				// sets the generated Container's height
		imgWidth: '870px',						// sets the width of the ImageBox/TextBox section. When subtracted from the Container's width - yields the Tabs width.
		tabsLocation: 'left',					// sets position of the Tabs (relative to the Image Box)
		tabBgImg: 'images/arrow-left.png',		// relative path for Image used as Highlighted Tab background (ie: the arrow)
		tabBgImgIE6: 'images/arrow-left.gif',	// relative path for Image used by IE6 (to prevent PNG alpha issues). Leave blank ('') or set to null to uses the same image (and to teach IE6 users a lesson).
		tabControl: 'click',					// sets the event that activates the tab change: 'click', 'hover'
		txtBoxWidth: '285px', // sets the width of the Vertical TextBox
		txtBoxHorizontalHeight: '90px',			// sets the height of the Horizontal TextBox
		txtBoxOpacity: 1,						// sets the opcaity of the TextBox background (color set in CSS - default is #000000)
		activeTabIsLink: true,					// determines if the the Highlighted Tab is a link to said Tab's default destination (the original href)
		activeWindowIsLink: true,				// determines if the current ImageBackground and TextBox are links to the Tab's default destination (the original href)
		animateInOnLoad: true,					// determines if the Tab, ImageBackground, and TextBox animate In on page load or simply appear
		txtBoxAnimateInType: 'slideLeft',		// sets animation In type for vertical TextBoxes: 'blink', 'fade', 'slideUp', 'slideDown', 'slideLeft', 'slideRight'
		txtBoxAnimateOutType: 'slideRight',		// sets animation Out type for vertical TextBoxes: 'blink', 'fade', 'slideUp', 'slideDown', 'slideLeft', 'slideRight'
		txtBoxAnimateHorzAlt: true,				// allows horizontal txtBoxes to animate in/out differently
		txtBoxAnimateInHorzType: 'slideUp',		// sets animation In type for horizontal TextBoxes: 'blink', 'fade', 'slideUp', 'slideDown', 'slideLeft', 'slideRight'
		txtBoxAnimateOutHorzType: 'slideDown',	// sets animation Out type for horizontal TextBoxes: 'blink', 'fade', 'slideUp', 'slideDown', 'slideLeft', 'slideRight'
		txtBoxAnimateInDuration: 500,			// sets the duration for TextBox In animations (in milliseconds)
		txtBoxAnimateOutDuration: 500,			// sets the duration for TextBox Out animations (in milliseconds)
		txtBoxPauseBetweenInOut: 250,			// sets the duration for the pause between the current TextBox animating Out and the new TextBox animating In ('0' for no delay) (in milliseconds)
		imgBgsAnimateInDuration: 500,			// sets the duration for ImageBackground In animations (in milliseconds)
		imgBgsAnimateOutDuration: 500,			// sets the duration for ImageBackground Out animations (in milliseconds)
		tabsAnimateInDuration: 100,				// sets the duration for Tab In animations (in milliseconds)
		tabsAnimateWidth: '+=20',				// sets the relative pixel width difference to be animated (to reveal the arrow)
		autoPlay: false,						// determines if the tabs cycle automatically
		autoPlayInterval: 5000,					// sets the autoPlay interval
		pauseOnHover: true,						// pause the autoPlay when hovering on siteFeature
		endCreateFunction: null					// creates a userdefined Callback (with access to all plugin Options) that fires after everything has been written to the DOM but before events are bound.
	}; // end $.fn.siteFeature.defaults
	
	// The following 2 jQuery Extensions contain all of the custom In and Out animations.  
	$.fn.siteFeatureAnimationsOut = function(opts) {
		
		// checks if the current data is to be displayed Horizontally, whether it should be treated differently, and executes accordingly
		if( $(this).hasClass('horizontal') && opts.txtBoxAnimateHorzAlt ){
			var origAniStorage = opts.txtBoxAnimateOutType;
			opts.txtBoxAnimateOutType = opts.txtBoxAnimateOutHorzType
		}
		
		if(opts.txtBoxAnimateOutType == 'blink'){
			$(this).css({'opacity':'0','display':'none'});
		}
		
		if(opts.txtBoxAnimateOutType == 'fade'){
			$(this).animate({'opacity':'0'},opts.txtBoxAnimateOutDuration, function(){
				$(this).css({'display':'none'});
			});
		}
		
		if(opts.txtBoxAnimateOutType == 'slideUp'){
			if(!$(this).hasClass('horizontal')){
				$(this).stop().animate({'marginTop':'-' + opts.containerHeight},opts.txtBoxAnimateOutDuration, function(){
					$(this).css({'opacity':'0','margin-top':'0','display':'none'})
				});
			} else {
				$(this).css({'opacity':'1'}).slideUp(opts.txtBoxAnimateOutDuration, function(){
					$(this).css({'opacity':'0','display':'none'})
				});
			}
		}
		
		if(opts.txtBoxAnimateOutType == 'slideDown'){	
			$(this).stop().animate({'marginTop':opts.containerHeight},opts.txtBoxAnimateOutDuration, function(){
				$(this).css({'opacity':'0','margin-top':'0','display':'none'})
			});
		
		}
		
		if(opts.txtBoxAnimateOutType == 'slideLeft'){
			if(opts.tabsLocation == 'left'){
				if(!$(this).hasClass('horizontal')){
					$(this).css({'right':'auto','left':(parseInt(opts.imgWidth) - parseInt(opts.txtBoxWidth))})
						.children().each(function(){
							$(this).css({'width':$(this).width()});
						}).end()
						.css({'opacity':'1'}).stop().animate({'width':'0'},opts.txtBoxAnimateOutDuration, function(){
							$(this).css({'opacity':'0','width':opts.txtBoxWidth,'display':'none'});
						})
					;
				} else {
					$(this).children().each(function(){
						$(this).css({'width':$(this).width()});
					}).end()
					.css({'opacity':'1'}).stop().animate({'left':'-' + opts.imgWidth},opts.txtBoxAnimateOutDuration, function(){
						$(this).css({'opacity':'0','left':'0','display':'none'});
					});
				}	
			} else {
				$(this).css({'right':'auto','left':'0'}).stop().animate({'left':'-' + opts.imgWidth},opts.txtBoxAnimateOutDuration, function(){
					$(this).css({'opacity':'0','left':'0','display':'none'});
				});
			}
		}
		
		if(opts.txtBoxAnimateOutType == 'slideRight'){
			if(opts.tabsLocation == 'left'){
				if(!$(this).hasClass('horizontal')){
					$(this).css({'opacity':'1','left':'auto','right':'0'}).stop().animate({'right':'-' + opts.txtBoxWidth},opts.txtBoxAnimateOutDuration, function(){
						$(this).css({'opacity':'0','right':'0','display':'none'});
					});
				} else {
					$(this).css({'opacity':'1','left':'auto'}).stop().animate({'right':'-' + opts.imgWidth},opts.txtBoxAnimateOutDuration, function(){
						$(this).css({'opacity':'0','right':'0','display':'none'});
					});
				}
			} else {
				if(!$(this).hasClass('horizontal')){
					$(this).css({'left':'0px'}).stop().animate({'left':'-' + opts.txtBoxWidth},opts.txtBoxAnimateOutDuration, function(){
						$(this).css({'opacity':'0','display':'none','left':'0px'});
					});
				} else {
					$(this).css({'left':'0px'}).stop().animate({'left':'-' + opts.imgWidth},opts.txtBoxAnimateOutDuration, function(){
						$(this).css({'opacity':'0','display':'none','left':'0px'});
					});
				}
			}
		}
		
		// undoes the tempory Horizontal bindings.
		if( $(this).hasClass('horizontal') && opts.txtBoxAnimateHorzAlt ){
			opts.txtBoxAnimateOutType = origAniStorage;
		}
		return this;
	}; // end $.fn.siteFeatureAnimationsOut


	$.fn.siteFeatureAnimationsIn = function(opts) {
		// checks if the current data is to be displayed Horizontally, whether it should be treated differently, and executes accordingly
		if( $(this).hasClass('horizontal') && opts.txtBoxAnimateHorzAlt ){
			var origAniStorage = opts.txtBoxAnimateInType;
			opts.txtBoxAnimateInType = opts.txtBoxAnimateInHorzType
		}

		if(opts.txtBoxAnimateInType == 'blink'){
			$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
				$(this).css({'opacity':'1','display':'block'});
			});
		}
		
		if(opts.txtBoxAnimateInType == 'fade'){
			$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
				$(this).css({'display':'block'}).animate({'opacity':'1'},opts.txtBoxAnimateInDuration);
			});
		}
		
		if(opts.txtBoxAnimateInType == 'slideUp'){
			$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
				$(this).css({'display':'block','opacity':'1','margin-top':opts.containerHeight}).animate({'marginTop':'0'},opts.txtBoxAnimateInDuration);
			});
		
		}
		
		if(opts.txtBoxAnimateInType == 'slideDown'){
			if(!$(this).hasClass('horizontal')){
				$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
					$(this).css({'display':'block','opacity':'1','margin-top':'-' + opts.containerHeight}).animate({'marginTop':'0'},opts.txtBoxAnimateInDuration);
				});
			} else {
				$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
					$(this).css({'display':'block','opacity':'1'}).slideUp(0).slideDown(opts.txtBoxAnimateInDuration);
				});
			}
		}
		
		if(opts.txtBoxAnimateInType == 'slideLeft'){
			if(opts.tabsLocation == 'left'){
				if(!$(this).hasClass('horizontal')){
					$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
						$(this).css({'display':'block','opacity':'1','right':'-' + opts.txtBoxWidth}).animate({'right':'0'},opts.txtBoxAnimateInDuration);
					});
				} else {
					$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
						$(this).css({'display':'block','opacity':'1','left':'auto','right':'-' + opts.imgWidth}).animate({'right':'0'},opts.txtBoxAnimateInDuration);
					});
				}
			} else {
				if(!$(this).hasClass('horizontal')){
					$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
						$(this).css({'display':'block'}).children().each(function(){
							$(this).css({'width':$(this).width()});
						}).end()
						.css({'display':'block','opacity':'1','width':'0','left':'auto','right': parseInt(opts.imgWidth) - parseInt(opts.txtBoxWidth) })
						.animate({'width':opts.txtBoxWidth});
					});
				} else {
					$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
						$(this).css({'display':'block','opacity':'1','left':'auto','right':'-' + opts.imgWidth}).animate({'right':'0'},opts.txtBoxAnimateInDuration);
					});
				}
			}
		}
		
		if(opts.txtBoxAnimateInType == 'slideRight'){
			if(opts.tabsLocation == 'left'){
				if(!$(this).hasClass('horizontal')){
					$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
						$(this).css({'display':'block','right':'auto','left':(parseInt(opts.imgWidth) - parseInt(opts.txtBoxWidth))})
						.children().each(function(){
							$(this).css({'width':$(this).width()});
						}).end()
						.css({'opacity':'1','width':'0'}).animate({'width':opts.txtBoxWidth},opts.txtBoxAnimateInDuration)
					;														   
					});
				} else {
					$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
						$(this).css({'display':'block','right':'auto','left':'-' + opts.imgWidth})
							.children().each(function(){
								$(this).css({'width':$(this).width()});
							}).end()
							.css({'opacity':'1'}).animate({'left':'0'},opts.txtBoxAnimateInDuration)
						;
					});
				}
			} else {
				$(this).animate({'opacity':'0'},opts.txtBoxPauseBetweenInOut, function(){
					$(this).css({'display':'block','opacity':'1','left':'-' + opts.imgWidth}).animate({'left':'0'},opts.txtBoxAnimateInDuration);
				});
			}
		}
		
		// undoes the tempory Horizontal bindings.
		if( $(this).hasClass('horizontal') && opts.txtBoxAnimateHorzAlt ){
			opts.txtBoxAnimateInType = origAniStorage;
		}
		return this;
	}; // end $.fn.siteFeatureAnimationsIn

	// simple utility function to replicate jQuery's InnerHTML function but to include the containing Element
    function outerHTML(element) {
		return $('<div>').append( element.eq(0).clone() ).html();
	};

	// This function contains all of the DOM traversal and manipulation.  All part of Progressive Enhancement and Unobtrusive Javascript.
	function createFeature(opts,settings){
		
		// Injecting into the DOM wastes time. Write to memory (create a string) and inject once when finished
		var siteFeature;
		var txtBoxes = "<div id='" + opts.txtBoxIdPrefix + "Container'>";
		var imgBgs = "<div id='" + opts.imgBgIdPrefix + "Container'>";
		var tabs = "<div id='" + opts.tabIdPrefix + "Container'>";
		
		// allows a seperate "Arrow" image to be assigned to IE6 (to prevent transparency issues)
		if($.browser.msie && $.browser.version == 6){
			if(opts.tabBgImgIE6 != null || opts.tabBgImgIE6 != ''){
				opts.tabBgImg = opts.tabBgImgIE6;
			}
		}
		
		// Loop through each Item and create all necessary HTML
		obj.children().each(function(i){
			
			sfcurrent = $(this);
			cloned = sfcurrent.clone()
				.attr({id: opts.tabIdPrefix + i})
				.find('img').remove().end()
				.wrapInner('<div>')
				.prepend('<span></span>')
			;
			
			txtBoxes += outerHTML(cloned);
			imgBgs += '<div id="' + opts.tabIdPrefix + i + '" style="background-image:url(' + sfcurrent.find('img').attr('src') + '); width:' + opts.imgWidth + '; height:' + opts.containerHeight + ';"></div>';
			tabs += '<a href="#' + opts.tabIdPrefix + i + '" id="' + opts.tabIdPrefix + i + '"><span><span></span><img src="' + opts.tabBgImg + '"/></span><h4>' + sfcurrent.find('h3').text() + '</h4><p>' + sfcurrent.find('img').attr('title') + '</p></a>';

		}); // end Each

		txtBoxes += "</div>";
		imgBgs += "</div>";
		tabs += "</div>";
		siteFeature = (imgBgs + txtBoxes + tabs);
		
		// Clear the current HTML and inject the siteFeature HTML
		obj.empty().attr({'id':opts.outputElementId,'class':opts.tabsLocation}).css({'width':opts.containerWidth,'height':opts.containerHeight}).append(siteFeature);
		obj.addClass('SF-' + settings.which);
		
		// Callback for DOM manipulation before event binding
		if($.isFunction(opts.endCreateFunction)){
			opts.endCreateFunction.apply(this, [opts]);
		}
	} // end createFeature()


	// This is the function that customizes the recently inject HTML based on the plugin options
	function customizeFeature(opts,settings){
		var txtBoxes = $('#' + opts.txtBoxIdPrefix + 'Container',obj);
		var imgBgs = $('#' + opts.imgBgIdPrefix + 'Container',obj);
		var tabs = $('#' + opts.tabIdPrefix + 'Container',obj);
		
		// style the Images
		imgBgs.css({'width':opts.imgWidth,'height':opts.containerHeight});
		
		// style the tabs
		tabs.children().css({
			'width':(parseInt(opts.containerWidth) - parseInt(opts.imgWidth)),
			'height':( (parseInt(opts.containerHeight) / tabs.children().length) - (1 + (1 / tabs.children().length)) )
		}).children('span').css({
			'width':(parseInt(opts.containerWidth) - parseInt(opts.imgWidth)),
			'height':( (parseInt(opts.containerHeight) / tabs.children().length) - (1 + (1 / tabs.children().length)) )
		}).children('img').css({
			'left':( (opts.tabsLocation == 'left') ? parseInt(opts.containerWidth) - parseInt(opts.imgWidth) : '0' )
		}).prev().css({
			'width':(parseInt(opts.containerWidth) - parseInt(opts.imgWidth))
		});
		
		// style the text boxes
		txtBoxes
			.css({'width':opts.imgWidth,'height':'220px','top':'90px'})
			.children('div:not(.horizontal)').css({'width':opts.txtBoxWidth,'height':'100%'}).end()
			.children('div.horizontal').css({'width':opts.imgWidth,'height':opts.txtBoxHorizontalHeight,'top':(parseInt(opts.containerHeight) - parseInt(opts.txtBoxHorizontalHeight)),'left':'0px'}).end()
			.find('div span').css({'opacity':opts.txtBoxOpacity}).next().css({'opacity':'1'})
		;
	} // end customizeFeature()
	
	
	// This function binds all associated events
	function eventFeature(opts,settings){
		var siteFeature = obj;
		var txtBoxes = $('#' + opts.txtBoxIdPrefix + 'Container',obj).children();
		var imgBgs = $('#' + opts.imgBgIdPrefix + 'Container',obj).children();
		var tabs = $('#' + opts.tabIdPrefix + 'Container',obj).children();
		
		// to streamline the number of events and conditions... there is only one Click event and it gets called onLoad
		// all methods are chained... we begin with "all txtBoxes / imgBgs / tabs", then we filter to just the 'selected' item, animated it Out, revert back to the
		// "all txtBoxes / imgBgs / tabs" selector, filter to that which matches the clicked Tab, animate it In.
		// FYI: "this.hash" = is a great way to match an href (href="#item") with an element with a matching id (id="item"). It's the foundation for the tabbing used here. 

		tabs.click(function(e){
			// quick check to determine if this onLoad (the class 'selected' hasn't been set yet - happens onLoad)
			if(!tabs.hasClass('selected')){
				// if onLoad animations are turned on
				if(opts.animateInOnLoad){
					txtBoxes.css({'opacity':'0','display':'none'})
						.filter(this.hash)
						.siteFeatureAnimationsIn(opts)
					;
					
					imgBgs.css({'opacity':'0','display':'none'})
						.filter(this.hash)
						.css({'display':'block'}).animate({'opacity':'1'},opts.imgBgsAnimateInDuration,null)
					;
					
					tabs.filter(this.hash).children('span')
						.animate({'width':opts.tabsAnimateWidth},opts.tabsAnimateInDuration,null)
					;
				// if onLoad animations are turned off
				} else {
					txtBoxes.css({'opacity':'0','display':'none'})
						.filter(this.hash)
						.css({'opacity':'1','display':'block'})
					;
					
					imgBgs.css({'opacity':'0','display':'none'})
						.filter(this.hash)
						.css({'opacity':'1','display':'block'})
					;
					
					tabs.filter(this.hash).children('span')
						.animate({'width':opts.tabsAnimateWidth},0,null)
					;
				}
			// the following are called onClick (as opposed to onLoad)
			} else {
				// seperates a click to load a new tab v. a click on the current tab visit the original link
				if(!$(this).hasClass('selected')){
					var hash = this.hash;
					txtBoxes.filter('.selected')
						.siteFeatureAnimationsOut(opts)
						.end().filter(this.hash)
						.siteFeatureAnimationsIn(opts)
					;
					
					imgBgs.filter('.selected')
						.animate({'opacity':'0'},opts.imgBgsAnimateOutDuration, function(){
							$(this).css({'display':'none'});
						})
						.end().filter(this.hash)
						.css({'display':'block'}).animate({'opacity':'1'},opts.imgBgsAnimateInDuration)
					;
					
					tabs.filter('.selected').children('span').css({
							'width':(parseInt(opts.containerWidth) - parseInt(opts.imgWidth)),
							'display':'none'
						}).end().end()
						.filter(this.hash).children('span').animate({'width':opts.tabsAnimateWidth},opts.tabsAnimateInDuration)
					;

				// the tab clicked is already open - trigger the original link
				} else {
					
					if(opts.activeTabIsLink){
						window.location = txtBoxes.filter(this.hash).find('a').attr('href');
						return false;
					}
					
				}
				
			}
			siteFeature.find('.selected').removeClass('selected');
			siteFeature.find(this.hash).each(function(){
				$(this).addClass('selected');
			});
			return false;
		// the ".filter(':first').click()" is a chaining method for triggering an event onLoad but only after it has been bound.
		// in this case... after the click has been bound to the Tabs, click the first Tab in the selector list. 
		}).filter(':first').click();
		
		if($.browser.msie && $.browser.version == 6){
			if(txtBoxes.filter(':first').hasClass('horizontal')){
				txtBoxes.filter(':first').css({'height':opts.txtBoxHorizontalHeight});
			} else {
				txtBoxes.filter(':first').css({'height':opts.containerHeight});
			}
		}

		
		// binds a click to the ImgBg that calls the original link
		if(opts.activeWindowIsLink){
			$('#' + opts.txtBoxIdPrefix + 'Container').css({'cursor':'pointer'}).click(function(e){
				if(e.target.tagName == 'A'){
					return true;
				} else {
					var hash = tabs.filter('.selected').attr('href');
					var hashMark = hash.lastIndexOf('#');
					hash = hash.substring(hashMark, hash.length);
					window.location = txtBoxes.filter(hash).find('a').attr('href');
					return false;
					
				}
			});
		}
		
		// binds the AutoPlay
		if(opts.autoPlay){
			SiteFeatureAutoPlayInterval['which'+settings.which] = setInterval("siteFeatureAutoPlayer(" + settings.which + ")",opts.autoPlayInterval);
			
			if(opts.pauseOnHover){
				obj.hover(function(){
					clearInterval(SiteFeatureAutoPlayInterval['which'+settings.which]);
				},function(){
					SiteFeatureAutoPlayInterval['which'+settings.which] = setInterval("siteFeatureAutoPlayer(" + settings.which + ")",opts.autoPlayInterval);
				});
			}
			
		}
		
		if(opts.tabControl == 'hover'){
			tabs.mouseover(function(){
				if(!$(this).hasClass('selected')){
					var hash = this.hash;
					txtBoxes.filter('.selected')
						.siteFeatureAnimationsOut(opts)
						.end().filter(this.hash)
						.siteFeatureAnimationsIn(opts)
					;
					
					imgBgs.filter('.selected')
						.animate({'opacity':'0'},opts.imgBgsAnimateOutDuration, function(){
							$(this).css({'display':'none'});
						})
						.end().filter(this.hash)
						.css({'display':'block'}).animate({'opacity':'1'},opts.imgBgsAnimateInDuration)
					;
					
					tabs.filter('.selected').children('span').css({
							'width':(parseInt(opts.containerWidth) - parseInt(opts.imgWidth)),
							'display':'none'
						}).end().end()
						.filter(this.hash).children('span').animate({'width':opts.tabsAnimateWidth},0)
					;
				}
				
				siteFeature.find('.selected').removeClass('selected');
				siteFeature.find(this.hash).each(function(){
					$(this).addClass('selected');
				});
				
			});
		}
		
	} // end eventFeature()
	

})(jQuery);

// this is the AutoPlay function
var SiteFeatureAutoPlayInterval = [];
function siteFeatureAutoPlayer(id){
	var tabs = $('.SF-' + id).find('#' + $.fn.siteFeature.defaults.tabIdPrefix + 'Container').children();
	if( (tabs.length - 1) == tabs.index(tabs.filter('.selected'))){
		tabs.filter(':first').click();
	} else {
		tabs.filter('.selected').next().click();
	}
}
